<template>
  <div>
    <el-card class="box-card" style="margin-top: 10px;" shadow="never">
      <el-descriptions title="详情" size="medium" :column="4" >
        <el-descriptions-item label="状态">
          <span :class="'badge-status-do badge-status-'+agent.status"/>
          <dict-tag :options="dict.type.kw_agent_status" :value="agent.status"/>
        </el-descriptions-item>
        <el-descriptions-item label="安装用户">{{agent.username}}</el-descriptions-item>
        <el-descriptions-item label="安装目录">{{agent.installHome}}</el-descriptions-item>
        <el-descriptions-item label="日志目录">{{agent.logHome}}</el-descriptions-item>
        <el-descriptions-item label="版本">{{agent.version}}</el-descriptions-item>
        <el-descriptions-item label="安装时间">{{agent.createTime}}</el-descriptions-item>
        <el-descriptions-item label="最近可用时间">{{agent.lastActiveTime}}</el-descriptions-item>
      </el-descriptions>
    </el-card>
    <el-card style="margin-top: 20px;" shadow="never">
      <el-descriptions title="进程列表" size="medium" direction="vertical" :column="9" border>
        <el-descriptions-item label="进程 ID">{{agent.pid}}</el-descriptions-item>
        <el-descriptions-item label="名称">jwagent</el-descriptions-item>
        <el-descriptions-item label="启动命令">{{agent.commandArgs}}</el-descriptions-item>
        <el-descriptions-item label="操作系统用户">{{agent.username}}</el-descriptions-item>
        <el-descriptions-item label="端口号">{{agent.port}}</el-descriptions-item>
        <el-descriptions-item label="已运行时间">{{getHumanTime(agent.upTime)}}</el-descriptions-item>
        <el-descriptions-item label="最近可用时间">{{agent.lastActiveTime}}</el-descriptions-item>
        <el-descriptions-item label="状态">
          <dict-tag :options="dict.type.kw_agent_status" :value="agent.status"/>
        </el-descriptions-item>
        <el-descriptions-item label="操作"></el-descriptions-item>
      </el-descriptions>
    </el-card>
  </div>
</template>

<script>
import { listAgent } from "@/api/machine/machine";
export default {
  name: "MachineBasic",
  props:["machineId"],
  dicts: ['kw_agent_status'],
  comments:{
  },
  data() {
    return {
      agent:{},
    };
  },
  created() {
    this.getMachineAgent();
  },
  methods: {
    getMachineAgent(){
      let param ={"pageable":"no","machineId":this.machineId};
      listAgent(param).then( res => {
        if(res.rows && res.rows.length>0 ){
          this.agent = res.rows[0];
        }
      })
    },
    getHumanTime(time){
      if(time===""||time==="null"||!time){
        return "-";
      }
      let sec = parseInt(time);
      if(sec<60){
        return sec+"秒"
      }else if(sec<60*60){
        let min = parseInt(sec/60);
        return min+"分"+(sec%60)+"秒"
      }else if(sec<60*60*24){
        let hour = parseInt(sec/60/60);
        let min = parseInt((sec-60*60*hour)/60);
        return hour+"小时"+min+"分";
      }else{
        return sec+"秒"
      }
    },
  }
};
</script>
